package com.myplans.client.view.custom;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.myplans.client.util.CookieManager;
import com.myplans.shared.Plan;

public class PlanPanel extends HorizontalPanel {

	Label title = new Label();
	Label description = new Label();
	Label numberAttending = new Label();
	Button attendButton = new Button("Attend"); 
	boolean isAttending = false;
	Plan plan;
	
	public PlanPanel(Plan plan, boolean attending) {
		VerticalPanel vPanel = new VerticalPanel();
		this.plan = plan;
		title.setStyleName("planTitle");
		title.setText(plan.getName());
		description.setStyleName("planLocation");
		description.setText(plan.getLocation() + " - " + plan.getDate()); 
		vPanel.add(title);
		vPanel.add(description);
		if (attending) {
			setAttending(true);
		} else {
			setAttending(false);
		}
		if (plan.getAttendingUsers() != null) {
			numberAttending.setText(plan.getAttendingUsers().size() + " participants");
			numberAttending.setStyleName("planLocation");
			vPanel.add(numberAttending);
		}
		this.add(vPanel);
		if (CookieManager.getSessionId() != null) {
			this.add(attendButton);
		}
		this.setStyleName("planPanel");
	}

	public Label getTitleLabel() {
		return title;
	}

	public Plan getPlan() {
		return plan;
	}

	public Button getAttendButton() {
		return attendButton;
	}
	
	public void setAttending(boolean attending) {
		if (attending) {
			attendButton.setStyleName("myButton-Attending");
			attendButton.setText("Attending");
		} else {
			attendButton.setStyleName("myButton");
			attendButton.setText("Attend");
		}
		isAttending = attending;
	}

	public boolean isAttending() {
		return isAttending;
	}
}
